using UnityEngine;
using System.Collections;

public class CharacterStateStanding : CharacterState
{	
	public float m_fSpeed = 8.0f;
	
	// cover logic
	public float m_fDistanceToCover = 8.0f;
	public float m_fDistanceToCoverMomentum = 4.0f;
	public float m_fSecurityDistanceToCover = 0.5f;
	
	public override void enter()
	{
	}
	
	public override void update()
	{	
		Vector2 vLeftStick = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
		
		// character moves depending the camera, so use the forward's projection of the camera
		Vector3 vRealForward = sCameras.Instance.getOrbitTransform().forward;
		vRealForward.y = 0.0f;
		vRealForward.Normalize();
		c.setForward(vRealForward, Vector3.up);
		
		if (c.updateShotMode())
		{
			c.changeState<CharacterStateStandingShot>();
			return;
		}
		
		// find coberture
		if (Input.GetButtonDown("X"))
		{
			if (sCovers.Instance.findCovers(m_fDistanceToCover, m_fDistanceToCoverMomentum, m_fSecurityDistanceToCover))
			{
				return;
			}
		}
		
		// horizontal move
		Vector3 vMove = (vLeftStick.x * c.tCamera.right + vLeftStick.y * vRealForward) * m_fSpeed;
		c.oController.Move(vMove * Time.deltaTime);
		
		// vertical move
		c.updateVerticalPosition();
		
		// update shooting
		if (c.isShooting())
		{
			Transform tCamera = sCameras.Instance.getCameraTransform();
			sBullets.Instance.shot(tCamera.position, tCamera.forward, tCamera.up, new Vector2(0.1f, 0.1f));
		}	
	}
	
	public override void exit()
	{
		
	}
}
